package leetcode.easy;

import leetcode.base.ListNode;

/**
 * ClassName: $160_IntersectionNode
 * Description:
 * date: 2021-11-08 23:24
 *
 * @author liyifan
 */
public class $160_IntersectionNode {
    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null)
            return null;

        ListNode pA = headA;
        ListNode pB = headB;
        while (pA != pB) {
            pA = pA == null ? headB : pA.next;
            pB = pB == null ? headA : pB.next;
        }
        return pA;
    }
}
